import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== global declare
const { $Lazy, $fn } = window
// ===================================================================== Lazy
const Box 			= $Lazy.load(()=>import('#tp/box/box'))
const PreviewImage 	= $Lazy.state(()=>import('#private/pages/preview-image'), 1)
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:{},
		customHide: true,	// 控制自定义属性显示或隐藏
		formData: [
			{ label:'标本条码', 		name:'spec_code' },
			{ label:'实验号', 		name:'experiment_num'},
			// { label:'病理号', 	name:'experiment_num',
			{ label:'姓名', 		name:'patient_name'},
			{ label:'年龄', 		name:'age'},
			{ label:'性别', 		name:'sex_name'},
			{ label:'送检科室', 		name:'department_name'},
			{ label:'床号', 		name:'bed_no'},
			{ label:'送检医生', 		name:'doctor'},
			{ label:'受检人电话', 	name:'patient_phone'},
			{ label:'证件类型', 		name:'card_type_name'},
			{ label:'证件号', 		name:'card_no'},
			{ label:'采集日期', 		name:'coll_time_x'},
			{ label:'送检单位', 		name:'hosp_name'},
			{ label:'单位标识', 		name:'hosp_identification'},
			{ label:'标本性状', 		name:'spec_traits_name'},
			{ label:'临床诊断', 		name:'diagnosis_info' },
			{ label:'备注', 		name:'remark', type:'textarea', rows:3},
			// 病人基本信息 增加5个自定义字段 2021-10-15  --马婷
			{ hide:true,	custom:true, onClick:()=>{this.customClick()}},
			{ label:'备用1', 		name:'user_defined1', 	full:true,	hide:true },
			{ label:'备用2', 		name:'user_defined2', 	full:true,	hide:true },
			{ label:'备用3', 		name:'user_defined3', 	full:true,	hide:true },
			{ label:'备用4', 		name:'user_defined4', 	full:true, 	hide:true },
			{ label:'备用5', 		name:'user_defined5', 	full:true, 	hide:true },
			{ label:'备用6', 		name:'user_defined6', 	full:true, 	hide:true },
			{ label:'备用7', 		name:'user_defined7', 	full:true, 	hide:true },
			{ label:'备用8', 		name:'user_defined8', 	full:true, 	hide:true },
			{ label:'备用9', 		name:'user_defined9', 	full:true, 	hide:true },
			{ label:'备用10', 		name:'user_defined10', 	full:true, 	hide:true },
		]
	}
	
	componentDidMount(){
		let { mode } = this.props
		const { formData } = this.state
		const bool = [44013,44022,44021,44008,44029,44030,44032,44033].includes(mode)
		$fn.getRow(formData, 'experiment_num').label = bool ? '病理号' : '实验号'
		this.setState({ formData })
	}
	componentWillUnmount(){
		this.setState = () => false
	}
	
	// 点击展开或关闭自定义属性
	customClick = () => {
		const { customHide, formData } = this.state
		this.setState({customHide:!customHide},()=>{
			$fn.hideRows(formData,['user_defined1','user_defined2','user_defined3','user_defined4','user_defined5','user_defined6','user_defined7','user_defined8','user_defined9','user_defined10'], this.state.customHide)
			this.setState({formData})
		})
	}
	
	load = ({ case_info, spec_info, pic_path }) => {
		const { age_first_val, age_first_type, samp_date, samp_time } = case_info
		const { spec_traits_name } = spec_info
		
		case_info.age = age_first_val + age_first_type
		case_info.spec_traits_name = spec_traits_name
		case_info.coll_time_x = samp_date + ' ' + samp_time
		
		this.formRef.setValue(case_info)
		
		this.setState({ data: case_info, img:pic_path })
	}
	
	loading = bool => this.setState({ submitLoading: bool })
	
	controls = () => {
		const { img } = this.state
		return [
			{ label:'查看图片', disabled:!img, onClick:()=> this.previewRef.open(img) }
		]
	}
	
	reset = () => this.formRef.reset()
	
	render(){
		const { submitLoading, customHide } = this.state
		return (
			<>
				<Box title='人员详情' full style={{width:220}} scroll flex className='h' scrollClassName='pt10 pr5 person-form' contentClassName='pb10' controls={this.controls()} loading={submitLoading}>
					{
						SubmitForm.call(this,{ readOnly:true, itemClassName:'no-clear-item', full:true, labelWidth:'s6', mb:10, noholder:true, customHide } ) 
					}
				</Box>
				<PreviewImage onRef = { ref => this.previewRef = ref } />
			</>
		)
	}
}

export default Index